package mybatis.service.impl;

import mybatis.dao.GameDao;
import mybatis.entity.Game;

import mybatis.service.GameService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class GameServiceImpl implements GameService {
    @Autowired
    private GameDao gameDao;
    @Override
    public void addAll(List<Game> list) {
        for(Game game : list) {
            gameDao.add(game);
        }
    }

    @Override
    public List<Game> findNewGames(int currentPage) {
        List<Game> list = gameDao.findByNew();
        return list;
    }

    @Override
    public Game findByNumber(int number) {
        Game game = gameDao.findByNumber(number);
        return game;
    }

    @Override
    public void addGameFeature(int fid, int gid) {
        gameDao.addGameFeature(fid, gid);
    }
    @Override
    public void addGameType(int gid, int tid) {
        gameDao.addGameType(gid, tid);
    }

    @Override
    public void addGameLanguage(int gid, int lid) {;
        gameDao.addGameLanguage(gid, lid);
    }

    @Override
    public void addSrcs(String src, int gid) {
        gameDao.addSrcs(src, gid);
    }

    @Override
    public void addGameVoice(int gid, int vid) {
        gameDao.addGameVoice(gid, vid);
    }

    @Override
    public List<Game> findPageByTid(int tid, int currentPage) {
        List<Game> list = gameDao.findAllByTid(tid);
        return list;
    }

    @Override
    public Game findWholeGameById(int id) {;
        Game game = gameDao.findWholeGameById(id);
        return game;
    }

    public static void main(String[] args) {
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml");
        GameService gameService = applicationContext.getBean("gameServiceImpl", GameService.class);
        Game game = gameService.findWholeGameById(1);
        System.out.println(game);
    }
}
